package cn.dankal.lequ.commom.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Fred on 2016/4/25.
 */
public class RecyclerViewAdapter extends PagerAdapter {
    List<RecyclerView> recyclerViews;
    ArrayList<String> tablayout_titles;

    public RecyclerViewAdapter(List<RecyclerView> recyclerViews, ArrayList<String> titles) {
        this.recyclerViews = recyclerViews;
        this.tablayout_titles = titles;
    }

    @Override
    public int getCount() {
        return recyclerViews.size();

    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    //    是从ViewGroup中移出当前View
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView(recyclerViews.get(arg1));
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tablayout_titles.get(position);
    }

    @Override
    public Object instantiateItem(View arg0, int arg1) {
        ((ViewPager) arg0).addView(recyclerViews.get(arg1));
        return recyclerViews.get(arg1);

    }
}
